<?php

/*
 * 接口
 */

namespace Association\Logic;

class ServiceLogic {

    public function __construct() {
        import('Memcachectr');
        $this->m = \Think\Memcachectr::create();
        $this->c = D('mfxhdatas');
    }

    //创建请求token
    public function createToken() {
        $token = md5(time());
        $this->m->set('service_token',$token);
        return $token;
    }
    
    //获取请求token
    public function getToken(){
        return $this->m->get('service_token');
    }
    
    //验证签名
    public function verifySign(){
        $sign = trim($_GET['sign']);
        ksort($_POST);
        $str = '';
        foreach($_POST as $k=>$v){
            $str .= $k.'='.$v.'&';
        }
        if($sign != md5($this->getToken().substr($str,0,-1))){
            exit('error:签名错误');
        }
    }
    
    //插入一条店面备案数据
    public function addData($arr){
        return $this->c->add($arr);
    }
    
    public function search($register_no){
        $re = $this->m->get('service_shop_'.$register_no);
        if(!$re){
            $re = $this->c->where(array('zch'=>$register_no))->find();
            $this->m->set('service_shop_'.$register_no,$re);
        }
        return $re;
    }
    
    /*按名称查询美发店*/
    public function getByName($name){
        $re = $this->m->get('service_shop_by_name'.$name);
        if(!$re){
            $re = $this->c->where(array('qyqc'=>$name))->find();
            $this->m->set('service_shop_by_name'.$name,$re);
        }
        return $re;
    }

}
